package com.qr.freturn;

import java.util.Arrays;
import java.util.Comparator;

/**
 * 函数式接口作为方法的返回值
 */
public class FunctionReturn {

    public static Comparator<String> getCompartor(){
        /*
        return new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                //o2 - o1就是字符串降序排列
                return o2.length() - o1.length();
            }
        };
        */

        /*
        return (String o2,String o1)->{
            return o2.length()-o1.length();
        };
        */

        //按照字符串长度的倒序记性排序
        return (o1,o2)-> o2.length()-o1.length();

    }


    public static void main(String[] args) {

        String[] arrays = {"3333","6666232","44","55111111"};
        System.out.println(Arrays.toString(arrays));

        Arrays.sort(arrays,getCompartor());
        System.out.println(Arrays.toString(arrays));

    }
}
